package com.herench.bs.agent.impl;

import com.herench.bs.agent.IPersonAgent;
import com.herench.bs.core.TokenProvider;
import com.herench.bs.dao.*;
import com.herench.bs.support.CleverClinicContext;
import com.herench.bs.support.DeployEvEnum;
import com.herench.bs.support.ResponseMessage;
import com.herench.bs.support.VerificationCodeSupport;
import com.herench.bs.transfer.Dialect;
import com.herench.bs.utils.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.*;

/**
 * @author luoxiaoming
 */
@Component
@Transactional(readOnly = true)
public class PersonAgent implements IPersonAgent {


    @Autowired
    private CleverClinicContext cleverClinicContext;

    @Autowired
    private IPersonDao personDao;

    @Autowired
    private ITreatmentCardDao treatmentCardDao;

    @Autowired
    private IUserDao userDao;

    @Autowired
    private IUserLoginAndLogoutRecordDao userLoginAndLogoutRecordDao;

    @Autowired
    private IPersonAndUserRelationDao personAndUserRelationDao;

    @Autowired
    private VerificationCodeSupport verificationCodeSupport;

    @Autowired
    private IDoctorDao doctorDao;

    @Autowired
    private IDeptDao deptDao;

    @Autowired
    private IEnshrineDao enshrineDao;

    @Autowired
    private IFeedBackDao feedBackDao;


    @Autowired
    private IDzSymptomDao dzSymptomDao;

    @Autowired
    private IDzSymMapDao dzSymMapDao;

    @Autowired
    private IDzSymMapperDao dzSymMapperDao;

    @Override
    public CleverClinicContext getCleverClinicContext() {
        return cleverClinicContext;
    }

    @Override
    public void setCleverClinicContext(CleverClinicContext cleverClinicContext) {
        this.cleverClinicContext = cleverClinicContext;
    }


    /**
     * 仅用手机号注册用户（不包含个人信息）
     *
     * @param phone            手机号
     * @param password         密码
     * @param verificationCode 手机验证码
     * @param channelCode      渠道编码
     * @param registerChannel  注册渠道
     * @param appImei          手机IMEI
     * @param webchat          微信号
     * @return 返回执行后的结果信息
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
    public Map<String, Object> phoneRegister(String phone, String password, String verificationCode, String channelCode, String registerChannel, String appImei, String webchat) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> personParams = new HashMap<>(16);
        personParams.put("phone", phone);
        personParams.put("username", phone);
        Map<String, Object> userMap = userDao.findOne(personParams);
        if (userMap != null) {
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE_IN, "手机号已经被占用");
            res.put(ResponseMessage.MESSAGE, "手机号已经被占用");
            res.put(ResponseMessage.MESSAGE_OUT, "手机号已经被占用");
            return res;
        } else {
//            if (getCleverClinicContext().getContextConfig().getDeployEv().equals(DeployEvEnum.publish)) {
//            this.verificationCodeSupport.checkVerificationCode(channelCode, phone, verificationCode);
//            }
            Map<String, Object> userParams = new HashMap<>(16);
            userParams.put("username", phone);
            userParams.put("registerDate", DataFormatUtils.getTimeString(new Date()));
            userParams.put("phone", phone);
            userParams.put("password", MD5Util.string2MD5(MD5Util.string2MD5(password)));
            userParams.put("webchat", webchat);
            userParams.put("state", "1");
            this.userDao.add(userParams);
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "注册成功");
            res.put(ResponseMessage.MESSAGE, "注册成功");
            res.put(ResponseMessage.MESSAGE_OUT, "注册成功");
        }
        return res;
    }

    /**
     * 注册用户（包含个人信息）
     *
     * @param name             姓名
     * @param phone            手机号
     * @param idCard           身份证号
     * @param password         密码
     * @param verificationCode 手机验证码
     * @param channelCode      渠道编码
     * @param registerChannel  注册渠道
     * @param appImei          手机IMEI
     * @param webchat          微信号
     * @return 返回执行后的结果信息
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
    public Map<String, Object> personRegister(String name, String phone, String idCard, String password, String verificationCode, String channelCode, String registerChannel, String appImei, String webchat) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> personParams = new HashMap<>(16);
        personParams.put("name", name);
        personParams.put("phone", phone);
        personParams.put("username", phone);
        personParams.put("idCard", idCard);
        personParams.put("personId", idCard);
        Map<String, Object> userMap = userDao.findOne(personParams);
        if (userMap != null) {
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE_IN, "手机号已经被占用");
            res.put(ResponseMessage.MESSAGE_OUT, "手机号已经被占用");
            res.put(ResponseMessage.MESSAGE, "手机号已经被占用");
            return res;
        } else {
            if (getCleverClinicContext().getContextConfig().getDeployEv().equals(DeployEvEnum.publish)) {
                verificationCodeSupport.checkVerificationCode(channelCode, phone, verificationCode);
            }
            Map<String, Object> persistPersonMap = personDao.findOne(personParams);
            if (persistPersonMap == null) {
                personParams.put("channelCode", channelCode);
                personParams.put("registerChannel", registerChannel);
                personParams.put("appImei", appImei);
                personParams.put("webchat", webchat);
                personParams.put("phone", phone);
                personParams.put("auth", "1");
                personParams.put("state", "1");
                personParams.put("sex", IdCardUtils.getSexByIdCard(idCard));
                personParams.put("createDate", DataFormatUtils.getTimeString(new Date()));
                personParams.put("dateOfBirth", IdCardUtils.getBirthdayByIdCard(idCard));
                personParams.put("dataStatus", "1");
                personParams.put("hospitalCode", "0001");
                personParams.put("relatedUserId", phone);
                personDao.add(personParams);
            }
            Map<String, Object> userParams = new HashMap<>(16);
            userParams.put("username", phone);
            userParams.put("idCard", idCard);
            userParams.put("registerDate", DataFormatUtils.getTimeString(new Date()));
            userParams.put("phone", phone);
            userParams.put("password", MD5Util.string2MD5(MD5Util.string2MD5(password)));
            userParams.put("webchat", webchat);
            userParams.put("state", "1");
            userParams.put("name", name);
            this.userDao.add(userParams);
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "注册成功");
            res.put(ResponseMessage.MESSAGE_OUT, "注册成功");
            res.put(ResponseMessage.MESSAGE, "注册成功");
        }
        return res;
    }

    /**
     * 注册用户(供非手机终端使用)
     *
     * @param name            姓名
     * @param phone           手机号
     * @param idCard          身份证号
     * @param password        密码
     * @param hospitalCode    注册所用的医院代码
     * @param registerChannel 注册渠道
     * @return 返回执行后的结果信息
     */
    @Override
    public Map<String, Object> register(String name, String phone, String idCard, String password, String hospitalCode, String registerChannel) {
        return null;
    }

    /**
     * 重置密码(供非手机终端使用)
     *
     * @param phone            姓名
     * @param personId         用户id
     * @param verificationCode 验证码
     * @param password         密码
     * @return 返回执行后的结果信息
     */
    @Override
    public Map<String, Object> resetPassword(String phone, String personId, String verificationCode, String password) {
        return null;
    }

    /**
     * 重置密码
     *
     * @param phone    姓名
     * @param personId 用户id
     * @param password 密码
     * @return 返回执行后的结果信息
     */
    @Override
    public Map<String, Object> resetPassword(String phone, String personId, String password) {
        return null;
    }

    /**
     * 重置密码(仅限于超级管理员|非手机终端使用)
     *
     * @param phone    姓名
     * @param password 密码
     * @return 返回执行后的结果信息
     */
    @Override
    public Map<String, Object> resetPassword(String phone, String password) {
        return null;
    }

    /**
     * 根据验证码修改密码
     *
     * @param channelCode      渠道编码
     * @param user             用户id
     * @param oldPassword      老密码
     * @param newPassword      新密码
     * @param verificationCode 手机验证码
     * @return 返回执行后的结果信息
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
    public Map<String, Object> modifyPassword(String channelCode, String user, String oldPassword, String newPassword, String verificationCode) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> personParams = new HashMap<>(16);
        personParams.put("username", user);
        Map<String, Object> userMap = userDao.findOne(personParams);
        String newPasswordMd5 = MD5Util.string2MD5(MD5Util.string2MD5(newPassword));
        if (userMap == null) {
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE_IN, "未查询到用户");
            res.put(ResponseMessage.MESSAGE_OUT, "未查询到用户");
            res.put(ResponseMessage.MESSAGE, "未查询到用户");
        } else {
//            this.verificationCodeSupport.checkVerificationCode(channelCode, user, verificationCode);
            Map<String, Object> userParams = new HashMap<>(16);
            userParams.put("username", user);
            userParams.put("password", newPasswordMd5);
            userParams.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
            this.userDao.modify(userParams);
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "操作成功");
            res.put(ResponseMessage.MESSAGE_OUT, "操作成功");
            res.put(ResponseMessage.MESSAGE, "操作成功");
        }
        return res;
    }

    /**
     * 修改姓名
     *
     * @param personId 用户id
     * @param name     新姓名
     * @return 返回执行后的结果信息
     */
    @Override
    public Map<String, Object> modifyInfo(String personId, String name) {
        return null;
    }

    /**
     * 修改用户基本信息
     *
     * @param user   用户
     * @param idCard 新身份证id
     * @param name   新姓名
     * @return 返回执行后的结果信息
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
    public Map<String, Object> modifyInfoByIdCard(String user, String idCard, String name) {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> params = new HashMap<>(16);
        params.put("username", user);
        params.put("idCard", idCard);
        params.put("name", name);
        userDao.modify(params);
        res.put(ResponseMessage.RES_CODE, "0");
        res.put(ResponseMessage.MESSAGE_IN, "操作成功");
        res.put(ResponseMessage.MESSAGE_OUT, "操作成功");
        res.put(ResponseMessage.MESSAGE, "操作成功");
        return res;
    }

    /**
     * 修改手机号
     *
     * @param personId 用户id
     * @param phone    手机号
     * @return 返回执行后的结果信息
     */
    @Override
    public Map<String, Object> modifyPhone(String personId, String phone) {
        return null;
    }

    /**
     * 修改用户状态
     *
     * @param personId 用户id
     * @param state    状态
     * @return 返回执行后的结果信息
     */
    @Override
    public Map<String, Object> modifyState(String personId, String state) {
        return null;
    }

    /**
     * 修改用户认证状态
     *
     * @param personId 用户id
     * @param auth     认证状态
     * @return 返回执行后的结果信息
     */
    @Override
    public Map<String, Object> modifyAuth(String personId, String auth) {
        return null;
    }

    /**
     * 添加就诊卡
     *
     * @param channelCode 渠道编码
     * @param idCard      患者身份证
     * @param cardType    卡类别
     * @param cardNum     卡号
     * @param defaultFlag 是否默认卡
     * @return 返回执行后的结果信息
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
    public Map<String, Object> addTreatmentCard(String channelCode, String idCard, String cardType, String cardNum, String defaultFlag) {
        Map<String, Object> res = new HashMap<>();
        Map<String, Object> params = new HashMap<>();
        params.put("cardId", IdGenerator.getUUID());
        params.put("idCard", idCard);
        params.put("cardType", cardType);
        params.put("cardNum", cardNum);
        params.put("defaultFlag", defaultFlag);
        List<Map<String, Object>> persistData = treatmentCardDao.find(params);
        if (persistData != null && persistData.size() > 0) {
            res.put(ResponseMessage.RES_CODE, "-2");
            res.put(ResponseMessage.MESSAGE_IN, "此卡已经绑定");
            res.put(ResponseMessage.MESSAGE_OUT, "此卡已经绑定");
            res.put(ResponseMessage.MESSAGE, "此卡已经绑定");
        } else {
            treatmentCardDao.add(params);
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "绑定成功");
            res.put(ResponseMessage.MESSAGE_OUT, "绑定成功");
            res.put(ResponseMessage.MESSAGE, "绑定成功");
        }
        return res;
    }

    /**
     * 修改就诊卡
     *
     * @param personId 患者用户id
     * @param cardType 卡类别
     * @param cardNum  卡号
     * @return 返回执行后的结果信息
     */
    @Override
    public Map<String, Object> modifyTreatmentCard(String personId, String cardType, String cardNum) {
        return null;
    }

    /**
     * 删除就诊卡
     *
     * @param personId 患者用户id
     * @param cardType 卡类别
     * @param cardNum  卡号
     * @return 返回执行后的结果信息
     */
    @Override
    public Map<String, Object> deleteTreatmentCard(String personId, String cardType, String cardNum) {
        return null;
    }

    /**
     * 根据患者用户id查询就诊卡
     *
     * @param personId 患者用户id
     * @return 返回执行后的结果信息
     */
    @Override
    public Map<String, Object> loadTreatmentCard(String personId) {
        return null;
    }

    /**
     * 根据主用户添加子用户
     *
     * @param masterUserId     主用户id
     * @param name             姓名
     * @param idCard           身份证号
     * @param registerChannel  注册渠道
     * @param mobile           就诊人手机号
     * @param verificationCode 验证码
     * @param defaultFlag      是否默认就诊人：   "1" 默认就诊人  "0" 非默认就诊人
     * @param verifyPhone      核实手机：1核实 ；0 不核实
     * @return 返回执行后的结果信息
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
    public Map<String, Object> addRelatedUserId(String masterUserId, String name, String idCard, String registerChannel, String mobile, String verificationCode, String defaultFlag, String verifyPhone) {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> userParams = new HashMap<>(16);
        userParams.put("username", masterUserId);
        Map<String, Object> userRes = userDao.findOne(userParams);
        if (userRes == null) {
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE_IN, "用户不存在");
            res.put(ResponseMessage.MESSAGE_OUT, "用户不存在");
            res.put(ResponseMessage.MESSAGE, "用户不存在");
        } else {
            String bindingNumberStr = (String) userRes.get("bindingNumber");
            int bindingNumber = 0;
            if (StringUtils.hasLength(bindingNumberStr)) {
                bindingNumber = Integer.parseInt(bindingNumberStr);
            }
            if (bindingNumber < Dialect.getMaxBindingNumber()) {
                try {
                    Map<String, Object> params = new HashMap<>(16);
                    Map<String, Object> relatedParams = new HashMap<>(16);
                    params.put("personId", idCard);
                    params.put("idCard", idCard);
                    Map<String, Object> personMap = personDao.findOne(params);
                    relatedParams.put("relatedUserId", masterUserId);
                    relatedParams.put("personId", idCard);
                    relatedParams.put("state", "1");
                    Map<String, Object> relatedRes = personAndUserRelationDao.findOne(relatedParams);
                    params.put("phone", mobile);
                    params.put("name", name);
                    params.put("state", "1");
                    if (relatedRes == null) {
//                        if (!(masterUserId.equals(mobile) && "0".equals(verifyPhone))) {
//                            verificationCodeSupport.checkVerificationCode(registerChannel, mobile, verificationCode);
//                        }


                        Map<String, Object> relatedParams1 = new HashMap<>(16);
                        relatedParams1.put("relatedUserId", masterUserId);
                        relatedParams1.put("personId", idCard);
                        relatedParams1.put("state", "2");
                        Map<String, Object> relatedRes1 = personAndUserRelationDao.findOne(relatedParams1);
                        if(relatedRes1!=null){
                            relatedParams1.put("channel", registerChannel);
                            relatedParams1.put("oldState","2");
                            relatedParams1.put("newState","1");
                            relatedParams1.put("verificationState","0");
                            relatedParams1.put("createTime", DataFormatUtils.getTimeString(new Date()));
                            this.personAndUserRelationDao.modify(relatedParams1);
                            userParams.put("bindingNumber", bindingNumber + 1);
                            userParams.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
                            userDao.modify(userParams);
                            res.put(ResponseMessage.RES_CODE, "0");
                            res.put(ResponseMessage.MESSAGE_IN, "添加成功");
                            res.put(ResponseMessage.MESSAGE_OUT, "添加成功");
                            res.put(ResponseMessage.MESSAGE, "添加成功");
                        }
                        else {

                            params.put("hospitalCode", "0001");
                            params.put("createDate", DataFormatUtils.getTimeString(new Date()));
                            params.put("sex", IdCardUtils.getSexByIdCard(idCard));
                            params.put("registerChannel", registerChannel);
                            params.put("dateOfBirth", IdCardUtils.getBirthdayByIdCard(idCard));
                            params.put("dataStatus", "1");
                            if (personMap == null) {
                                this.personDao.add(params);
                            } else if (!personMap.get("state").equals("1")) {
                                throw new Exception("此就诊人信息异常,请联系客服");
                            }
                            relatedParams.put("channel", registerChannel);
                            relatedParams.put("createTime", DataFormatUtils.getTimeString(new Date()));
                            this.personAndUserRelationDao.add(relatedParams);
                            if ("1".equals(defaultFlag)) {
                                userParams.put("personId", idCard);
                            }
                            userParams.put("bindingNumber", bindingNumber + 1);
                            userParams.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
                            userDao.modify(userParams);
                            res.put(ResponseMessage.RES_CODE, "0");
                            res.put(ResponseMessage.MESSAGE_IN, "添加成功");
                            res.put(ResponseMessage.MESSAGE_OUT, "添加成功");
                            res.put(ResponseMessage.MESSAGE, "添加成功");

                        }


//
//                        params.put("hospitalCode", "0001");
//                        params.put("createDate", DataFormatUtils.getTimeString(new Date()));
//                        params.put("sex", IdCardUtils.getSexByIdCard(idCard));
//                        params.put("registerChannel", registerChannel);
//                        params.put("dateOfBirth", IdCardUtils.getBirthdayByIdCard(idCard));
//                        params.put("dataStatus", "1");
//                        if (personMap == null) {
//                            this.personDao.add(params);
//                        } else if (!personMap.get("state").equals("1")) {
//                            throw new Exception("此就诊人信息异常,请联系客服");
//                        }
//                        relatedParams.put("channel", registerChannel);
//                        relatedParams.put("createTime", DataFormatUtils.getTimeString(new Date()));
//                        this.personAndUserRelationDao.add(relatedParams);
//                        if ("1".equals(defaultFlag)) {
//                            userParams.put("personId", idCard);
//                        }
//                        userParams.put("bindingNumber", bindingNumber + 1);
//                        userParams.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
//                        userDao.modify(userParams);
//                        res.put(ResponseMessage.RES_CODE, "0");
//                        res.put(ResponseMessage.MESSAGE_IN, "添加成功");
//                        res.put(ResponseMessage.MESSAGE_OUT, "添加成功");
//                        res.put(ResponseMessage.MESSAGE, "添加成功");
                    } else {



//                        Map<String, Object> relatedParams1 = new HashMap<>(16);
//                        relatedParams1.put("relatedUserId", masterUserId);
//                        relatedParams1.put("personId", idCard);
//                        relatedParams1.put("state", "2");
//                        Map<String, Object> relatedRes1 = personAndUserRelationDao.findOne(relatedParams);
//                        if(relatedRes1!=null){
//                            relatedParams.put("channel", registerChannel);
//                            relatedParams.put("newState","1");
//                            relatedParams.put("createTime", DataFormatUtils.getTimeString(new Date()));
//                            this.personAndUserRelationDao.modify(relatedParams);
//                            userParams.put("bindingNumber", bindingNumber + 1);
//                            userParams.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
//                            userDao.modify(userParams);
//                            res.put(ResponseMessage.RES_CODE, "0");
//                            res.put(ResponseMessage.MESSAGE_IN, "添加成功");
//                            res.put(ResponseMessage.MESSAGE_OUT, "添加成功");
//                            res.put(ResponseMessage.MESSAGE, "添加成功");
//                        }
//                        else {
                        res.put(ResponseMessage.RES_CODE, "-1");
                        res.put(ResponseMessage.MESSAGE_IN, "此就诊人已绑定");
                        res.put(ResponseMessage.MESSAGE_OUT, "此就诊人已绑定");
                        res.put(ResponseMessage.MESSAGE, "此就诊人已绑定");
//                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    res.put(ResponseMessage.RES_CODE, "-3");
                    res.put(ResponseMessage.MESSAGE, e.getMessage());
                    res.put(ResponseMessage.MESSAGE_IN, e.getMessage());
                    res.put(ResponseMessage.MESSAGE_OUT, e.getMessage());
                }
            } else {
                res.put(ResponseMessage.RES_CODE, "-1");
                res.put(ResponseMessage.MESSAGE_IN, "绑定失败，该用户绑定人数已达到" + Dialect.getMaxBindingNumber() + "人");
                res.put(ResponseMessage.MESSAGE_OUT, "绑定失败，该用户绑定人数已达到" + Dialect.getMaxBindingNumber() + "人");
                res.put(ResponseMessage.MESSAGE, "绑定失败，该用户绑定人数已达到" + Dialect.getMaxBindingNumber() + "人");
            }
        }
        return res;
    }

    /**
     * 根据主用户删除子用户
     *
     * @param masterUserId 主用户id
     * @param name         姓名
     * @param idCard       身份证号
     * @return 返回执行后的结果信息
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
    public Map<String, Object> removeRelatedUser(String masterUserId, String name, String idCard) {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> params = new HashMap<>(16);
        if (StringUtils.hasLength(masterUserId) && StringUtils.hasLength(idCard)) {
            params.put("username", masterUserId);
            Map<String, Object> userRes = this.userDao.findOne(params);
            if (userRes == null) {
                res.put(ResponseMessage.RES_CODE, "-1");
                res.put(ResponseMessage.MESSAGE_IN, "未查询到用户");
                res.put(ResponseMessage.MESSAGE_OUT, "未查询到用户");
                res.put(ResponseMessage.MESSAGE, "未查询到用户");
            } else {
                Map<String, Object> relatedParams = new HashMap<>(16);
                relatedParams.put("relatedUserId", masterUserId);
                relatedParams.put("personId", idCard);
                relatedParams.put("state", "1");
                Map<String, Object> resRelated = personAndUserRelationDao.findOne(relatedParams);
                if (resRelated != null) {
                    //若此就诊人为默认就诊人，将默认就诊人personId字段置空。
                    if (StringUtils.hasLength((String) userRes.get("personId"))) {
                        if (userRes.get("personId").equals(idCard)) {
                            params.put("personId", "");
                        }
                    }
                    //减掉一个就诊人绑定数
                    if (StringUtils.hasLength((String) userRes.get("bindingNumber"))) {
                        int bindingNumber = Integer.parseInt((String) userRes.get("bindingNumber"));
                        if (bindingNumber > 0) {
                            bindingNumber = bindingNumber - 1;
                        }
                        params.put("bindingNumber", bindingNumber);
                    }
                    this.userDao.modify(params);
                    relatedParams.remove("state");
                    relatedParams.put("newState", "2");
                    relatedParams.put("oldState", "1");
                    relatedParams.put("unbundledTime", DataFormatUtils.getTimeString(new Date()));
                    relatedParams.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
                    this.personAndUserRelationDao.modify(relatedParams);
                    res.put(ResponseMessage.RES_CODE, "0");
                    res.put(ResponseMessage.MESSAGE_IN, "操作成功");
                    res.put(ResponseMessage.MESSAGE_OUT, "操作成功");
                    res.put(ResponseMessage.MESSAGE, "操作成功");
                } else {
                    res.put(ResponseMessage.RES_CODE, "0");
                    res.put(ResponseMessage.MESSAGE_IN, "该就诊人已解除绑定");
                    res.put(ResponseMessage.MESSAGE_OUT, "该就诊人已解除绑定");
                    res.put(ResponseMessage.MESSAGE, "该就诊人已解除绑定");
                }
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE_IN, "用户名和就诊人身份证不得为空");
            res.put(ResponseMessage.MESSAGE_OUT, "用户名和就诊人身份证不得为空");
            res.put(ResponseMessage.MESSAGE, "用户名和就诊人身份证不得为空");
        }
        return res;
    }

    /**
     * 根据主用户查询子用户列表
     *
     * @param masterUserId 主用户id
     * @return 返回执行后的结果信息
     */
    @Override
    public Map<String, Object> loadRelatedUsers(String masterUserId) {
        Map<String, Object> res = new HashMap<>();
        Map<String, Object> params = new HashMap<>();
        params.put("relatedUserId", masterUserId);
        params.put("state", "1");
        List<Map<String, Object>> personList = this.personAndUserRelationDao.find(params);
        List<Map<String, Object>> data = new ArrayList<>();
        params.remove("relatedUserId");
        params.put("username", masterUserId);
        Map<String, Object> userRes = this.userDao.findOne(params);
        if (personList != null && userRes != null) {
            for (Map<String, Object> el : personList) {
                Map<String, Object> temp = new HashMap<>(16);
                Map<String, Object> personParams = new HashMap<>(16);
                personParams.put("personId", el.get("personId"));
                Map<String, Object> personRes = personDao.findOne(personParams);
                temp.put("verificationState", el.get("verificationState"));

                if (personRes != null) {
                    temp.put("name", personRes.get("name"));
                    temp.put("idCard", personRes.get("idCard"));
                    temp.put("mobile", personRes.get("phone"));
                    temp.put("sex", personRes.get("sex"));
                    temp.put("insurNo", personRes.get("insurNo"));
                    temp.put("dateOfBirth", DataFormatUtils.getSimpleTimeString((Date) personRes.get("dateOfBirth")));
                    String personId = (String) userRes.get("personId");
                    if (personId != null) {
                        if (personId.equals(personRes.get("idCard"))) {
                            //"isDefault", "1" 默认就诊人
                            temp.put("isDefault", "1");
                        } else {
                            //"isDefault", "0" 非默认就诊人
                            temp.put("isDefault", "0");
                        }
                    } else {
                        //"isDefault", "0" 非默认就诊人
                        temp.put("isDefault", "0");
                    }
                }
                if (!temp.isEmpty()) {
                    data.add(temp);
                }
            }
            if (data != null && data.size() >= 2) {
                Collections.sort(data, new Comparator<Map<String, Object>>() {
                    @Override
                    public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                        return o2.get("isDefault").toString().compareTo(o1.get("isDefault").toString());
                    }
                });
            }
        }
        res.put("personList", data);
        res.put(ResponseMessage.RES_CODE, "0");
        res.put(ResponseMessage.MESSAGE_IN, "查询成功");
        res.put(ResponseMessage.MESSAGE_OUT, "查询成功");
        res.put(ResponseMessage.MESSAGE, "查询成功");
        return res;
    }

    /**
     * 根据患者用户id和医院代码添加使用授权
     *
     * @param personId     患者用户id
     * @param hospitalCode 医院代码
     * @param authWays     授权渠道
     * @param mark         备注
     * @return 返回执行后的结果信息
     */
    @Override
    public Map<String, Object> addHospitalAccessAuth(String personId, String hospitalCode, String authWays, String mark) {
        return null;
    }

    /**
     * 根据患者用户id和医院代码删除使用授权信息
     *
     * @param personId     患者用户id
     * @param hospitalCode 医院代码
     * @return 返回执行后的结果信息
     */
    @Override
    public Map<String, Object> deleteHospitalAccessAuth(String personId, String hospitalCode) {
        return null;
    }

    /**
     * 上传头像
     *
     * @param personId       患者用户id
     * @param avatarFilePath 头像文件路径
     * @return 返回执行后的结果信息
     */
    @Override
    public Map<String, Object> uploadAvatar(String personId, String avatarFilePath) {
        return null;
    }

    /**
     * 添加收藏
     *
     * @param channelCode    渠道编码
     * @param user           患者用户id
     * @param collectType    收藏类型
     * @param collectContent 收藏代码
     * @return 返回执行后的结果
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
    public Map<String, Object> addEnshrine(String channelCode, String user, String collectType, String collectContent) {
        Map<String, Object> res = new HashMap<>();
        Map<String, Object> params = new HashMap<>();
        try {
            params.put("channelCode", channelCode);
            params.put("userId", user);
            params.put("collectType", collectType);
            params.put("collectContent", collectContent);
            List<Map<String, Object>> enshrines = enshrineDao.find(params);
            params.put("createTime", new Date());
            params.put("enshrineId", UUID.randomUUID().toString());
            if (enshrines.isEmpty()) {
                if (collectType.equals("1")) {
                    params.put("doctorCode", collectContent);
                    Map<String, Object> doctorMap = doctorDao.findOne(params);
                    params.put("collectContentText", doctorMap.get("doctorName"));
                }
                if (collectType.equals("2")) {
                    params.put("deptCode", collectContent);
                    Map<String, Object> doctorMap = deptDao.findOne(params);
                    params.put("collectContentText", doctorMap.get("deptName"));
                }
                enshrineDao.add(params);
            }
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "添加成功");
            res.put(ResponseMessage.MESSAGE_OUT, "添加成功");
            res.put(ResponseMessage.MESSAGE, "添加成功");
        } catch (Exception e) {
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE_IN, "添加出错");
            res.put(ResponseMessage.MESSAGE_OUT, "添加出错");
            res.put(ResponseMessage.MESSAGE, "添加出错");
            e.printStackTrace();
        }
        return res;
    }

    /**
     * 删除收藏内容
     *
     * @param collectContent 医生id
     * @param userId
     * @return 返回执行后的结果
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
    public Map<String, Object> deleteEnshrine(String collectContent, String userId) {
        Map<String, Object> res = new HashMap<>();
        Map<String, Object> params = new HashMap<>();
        try {
            String enshrineId = "无";
            params.put("collectContent", collectContent);
            params.put("userId", userId);
            params.put("collectType", "1");
            Map<String, Object> resEnshrineDao = enshrineDao.findOne(params);
            if (resEnshrineDao != null) {
                enshrineId = (String) resEnshrineDao.get("enshrineId");
            }
            params.put("enshrineId", enshrineId);
            enshrineDao.delete(params);
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "操作成功");
            res.put(ResponseMessage.MESSAGE_OUT, "操作成功");
            res.put(ResponseMessage.MESSAGE, "操作成功");
        } catch (Exception e) {
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE_IN, "操作失败");
            res.put(ResponseMessage.MESSAGE_OUT, "操作失败");
            res.put(ResponseMessage.MESSAGE, "操作失败");
            e.printStackTrace();
        }
        return res;
    }

    /**
     * 加载收藏夹内容
     *
     * @param channelCode 渠道编码
     * @param userId      患者用户id
     * @return 返回执行后的结果
     */
    @Override
    public Map<String, Object> loadEnshrine(String channelCode, String userId) {
        Map<String, Object> res = new HashMap<>();
        Map<String, Object> params = new HashMap<>();
        String doctorCode = "无";
        String major = "无";
        String titleCode = "无";
        String sex = "无";
        String url = "无";
        String deptCode = "无";
        try {
            params.put("userId", userId);
            params.put("channelCode", channelCode);
            List<Map<String, Object>> dataList = new ArrayList<>();
            List<Map<String, Object>> data = enshrineDao.find(params);
            if (data != null && data.size() > 0) {
                for (Map<String, Object> dateSubMap : data) {
                    Map<String, Object> paramsMap = new HashMap<>(16);
                    paramsMap.put("docId", dateSubMap.get("collectContent"));
                    paramsMap.put("collectType", dateSubMap.get("collectType"));
                    paramsMap.put("docName", dateSubMap.get("collectContentText"));
                    paramsMap.put("enshrineId", dateSubMap.get("enshrineId"));
                    paramsMap.put("createTime", dateSubMap.get("createTime"));
                    paramsMap.put("user", dateSubMap.get("userId"));
                    paramsMap.put("channelCode", dateSubMap.get("channelCode"));
                    params.put("collectType", dateSubMap.get("collectType"));
                    params.put("collectContent", dateSubMap.get("collectContent"));
                    Map<String, Object> resEnshrineDao = enshrineDao.findOne(params);
                    doctorCode = (String) resEnshrineDao.get("collectContent");
                    params.put("doctorCode", doctorCode);
                    Map<String, Object> resDoctorDao = doctorDao.findOne(params);
                    if (resDoctorDao != null) {
                        major = (String) resDoctorDao.get("major");
                        sex = (String) resDoctorDao.get("sex");
                        url = (String) resDoctorDao.get("iconUrl");
                        titleCode = (String) resDoctorDao.get("titleCode");
                        deptCode = (String) resDoctorDao.get("deptCode");
                    }
                    params.put("deptCode", deptCode);
                    params.put("hospitalCode", "0001");
                    String deptName = "无";
                    Map<String, Object> reshospitalDeptDao = deptDao.findOne(params);
                    if (reshospitalDeptDao != null) {
                        deptName = (String) reshospitalDeptDao.get("deptName");
                    }
                    paramsMap.put("deptId", deptCode);
                    paramsMap.put("deptName", deptName);
                    paramsMap.put("sex", sex);
                    paramsMap.put("url", url);
                    paramsMap.put("titleName", Dialect.getDoctorTitleName(titleCode));
                    paramsMap.put("major", major);
                    dataList.add(paramsMap);
                }
                res.put("enshrineList", dataList);
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE_IN, "查询成功");
                res.put(ResponseMessage.MESSAGE_OUT, "查询成功");
                res.put(ResponseMessage.MESSAGE, "查询成功");

            } else {
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE_IN, "查询成功");
                res.put(ResponseMessage.MESSAGE_OUT, "查询成功");
                res.put(ResponseMessage.MESSAGE, "查询成功");

            }
        } catch (Exception e) {
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE_IN, "查询失败");
            res.put(ResponseMessage.MESSAGE_OUT, "查询失败");
            res.put(ResponseMessage.MESSAGE, "查询失败");
            e.printStackTrace();
        }
        return res;
    }

    @Override
    public Map<String, Object> checkEnshrineStatus(String userId, String collectContent, String collectType) {
        Map<String, Object> res = new HashMap<>();
        Map<String, Object> params = new HashMap<>();
        params.put("userId", userId);
        params.put("collectContent", collectContent);
        params.put("collectType", "1");
        Map<String, Object> paramsMap = new HashMap<>(16);
        Map<String, Object> resEnshrineDao = enshrineDao.findOne(params);
        try {
            if (resEnshrineDao != null) {
                paramsMap.put("status", "1");
            } else {
                paramsMap.put("status", "2");
            }
            res.put("enshrineList", paramsMap);
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "查询成功");
            res.put(ResponseMessage.MESSAGE_OUT, "查询成功");
            res.put(ResponseMessage.MESSAGE, "查询成功");
        } catch (Exception e) {
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE_IN, "查询失败");
            res.put(ResponseMessage.MESSAGE_OUT, "查询失败");
            res.put(ResponseMessage.MESSAGE, "查询失败");
            e.printStackTrace();
        }
        return res;
    }

    /**
     * 根据身份证密码登录
     *
     * @param channelCode 渠道编码
     * @param idCard      身份证号
     * @param password    密码
     * @return 返回执行后的结果
     */
    @Override
    public Map<String, Object> login(String channelCode, String idCard, String password) {
        Map<String, Object> res = new HashMap<>();
        return res;
    }

    /**
     * 根据身份证号验证码登录
     *
     * @param channelCode      渠道编码
     * @param idCard           身份证号
     * @param verificationCode 验证码
     * @return 返回执行后的结果
     */
    @Override
    public Map<String, Object> loginByIdCardAndVerificationCode(String channelCode, String idCard, String verificationCode) {
        return null;
    }

    /**
     * 根据手机号和验证码登录
     *
     * @param channelCode      渠道编码
     * @param phone            手机号
     * @param verificationCode 验证码
     * @return 返回执行后的结果
     */
    @Override
    public Map<String, Object> loginByPhoneAndVerificationCode(String channelCode, String phone, String verificationCode) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> params = new HashMap<>(16);
        params.put("username", phone);
//        TokenProvider.checkTokenLifeCycleIsLiveByUsername(phone);
        Map<String, Object> userMap = userDao.findOne(params);
        if (userMap == null) {
            res.put(ResponseMessage.RES_CODE, "-4");
            res.put(ResponseMessage.MESSAGE_IN, "帐号不存在");
            res.put(ResponseMessage.MESSAGE, "帐号不存在");
            res.put(ResponseMessage.MESSAGE_OUT, "帐号不存在");
        } else if (userMap.get("state").equals("0")) {
            res.put(ResponseMessage.RES_CODE, "-6");
            res.put(ResponseMessage.MESSAGE_IN, "账号已锁定");
            res.put(ResponseMessage.MESSAGE, "账号已锁定");
            res.put(ResponseMessage.MESSAGE_OUT, "账号已锁定");
        } else if (userMap.get("state").equals("-1")) {
            res.put(ResponseMessage.RES_CODE, "-7");
            res.put(ResponseMessage.MESSAGE_IN, "账号已作废");
            res.put(ResponseMessage.MESSAGE, "账号已作废");
            res.put(ResponseMessage.MESSAGE_OUT, "账号已作废");
        } else {
            Map<String, String> authMap = AuthHelper.validateVerificationCode(getCleverClinicContext().getContextConfig().getAuthUrl(), channelCode, phone, verificationCode);
            if (authMap != null && authMap.get("code") != null) {
                if (authMap.get("code").equals("0")) {
                    res.put(ResponseMessage.RES_CODE, "0");
                    res.put(ResponseMessage.MESSAGE_IN, "登录成功");
                    res.put(ResponseMessage.MESSAGE, "登录成功");
                    res.put(ResponseMessage.MESSAGE_OUT, "登录成功");
                    res.put("accessToken", TokenProvider.generatorToken(phone).getTokenKey());
                    res.put("lastLoginTime", DataFormatUtils.getTimeString(new Date()));
                } else {
                    res.put(ResponseMessage.RES_CODE, "-6");
                    res.put(ResponseMessage.MESSAGE_IN, "验证码无效");
                    res.put(ResponseMessage.MESSAGE, "验证码无效");
                    res.put(ResponseMessage.MESSAGE_OUT, "验证码无效");
                }
            } else {
                res.put(ResponseMessage.RES_CODE, "-7");
                res.put(ResponseMessage.MESSAGE_IN, "系统异常");
                res.put(ResponseMessage.MESSAGE, "系统异常");
                res.put(ResponseMessage.MESSAGE_OUT, "系统异常");
            }
        }
        return res;
    }


    /**
     * 根据手机号和密码登录
     *
     * @param channelCode 渠道编码
     * @param phone       手机号
     * @param passwd      密码
     * @param imei        移动设别imei编号
     * @param openId      微信或其他网页登录唯一身份识别码
     * @param source      来源：1.安卓，2.IOS  3微网站
     * @return 返回执行后的结果
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
    public Map<String, Object> loginByPhoneAndPasswd(String channelCode, String phone, String passwd, String imei, String openId, String source) {
        Map<String, Object> res = new HashMap<>();
        String decodePasswd = MD5Util.string2MD5(MD5Util.string2MD5(passwd));
        Map<String, Object> params = new HashMap<>();
        params.put("username", phone);
//        TokenProvider.checkTokenLifeCycleIsLiveByUsername(phone);
        Map<String, Object> userMap = userDao.findOne(params);
        if (userMap == null) {
            res.put(ResponseMessage.RES_CODE, "-4");
            res.put(ResponseMessage.MESSAGE_IN, "帐号不存在");
            res.put(ResponseMessage.MESSAGE, "帐号不存在");
            res.put(ResponseMessage.MESSAGE_OUT, "帐号不存在");
        } else if (decodePasswd.equalsIgnoreCase((String) userMap.get("password"))) {
            if (userMap.get("state").equals("0")) {
                res.put(ResponseMessage.RES_CODE, "-6");
                res.put(ResponseMessage.MESSAGE_IN, "账号已锁定");
                res.put(ResponseMessage.MESSAGE, "账号已锁定");
                res.put(ResponseMessage.MESSAGE_OUT, "账号已锁定");
            } else if (userMap.get("state").equals("-1")) {
                res.put(ResponseMessage.RES_CODE, "-7");
                res.put(ResponseMessage.MESSAGE_IN, "账号已作废");
                res.put(ResponseMessage.MESSAGE, "账号已作废");
                res.put(ResponseMessage.MESSAGE_OUT, "账号已作废");
            } else {
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE_IN, "登录成功");
                res.put(ResponseMessage.MESSAGE, "登录成功");
                res.put(ResponseMessage.MESSAGE_OUT, "登录成功");
                String nowDate = DataFormatUtils.getTimeString(new Date());
                res.put("accessToken", TokenProvider.generatorToken(phone).getTokenKey());
                res.put("lastLoginTime", nowDate);
                params.put("loginUser", phone);
                params.put("loginStatus", 0);
                List<Map<String, Object>> loginRes = userLoginAndLogoutRecordDao.find(params);
                if (loginRes.size() != 0) {
                    for (Map<String, Object> subMap : loginRes) {
                        if ("3".equals(source) && StringUtils.hasLength((String) subMap.get("openId"))) {
                            //loginStatus=3 : 因他人登录被注销
                            subMap.put("loginStatus", 3);
                            subMap.put("logoutTime", nowDate);
                            subMap.put("modifyTime", nowDate);
                            userLoginAndLogoutRecordDao.modify(subMap);
                        } else if (("1".equals(source) || "2".equals(source)) && StringUtils.hasLength((String) subMap.get("imei"))) {
                            //loginStatus=3 : 因他人登录被注销
                            subMap.put("loginStatus", 3);
                            subMap.put("logoutTime", nowDate);
                            subMap.put("modifyTime", nowDate);
                            userLoginAndLogoutRecordDao.modify(subMap);
                        }
                    }
                }
                String loginId = "LOGIN" + DataFormatUtils.getTimeStringNoSpace(new Date()) + channelCode + IdGenerator.getSixRandNum();
                params.put("loginId", loginId);
                if ("3".equals(source)) {
                    params.put("openId", openId);
                    params.put("openIdExpirationTime", DataFormatUtils.getFutureDate(30));
                } else {
                    params.put("imei", imei);
                    params.put("imeiExpirationTime", DataFormatUtils.getFutureDate(30));
                }
                params.put("loginTime", nowDate);
                params.put("modifyTime", nowDate);
                userLoginAndLogoutRecordDao.add(params);
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-5");
            res.put(ResponseMessage.MESSAGE_IN, "密码错误");
            res.put(ResponseMessage.MESSAGE, "密码错误");
            res.put(ResponseMessage.MESSAGE_OUT, "密码错误");
        }
        return res;
    }

    /**
     * 根据手机号和验证码登录
     *
     * @param channelCode      渠道编码
     * @param phone            手机号
     * @param webchat          微信号
     * @param verificationCode 验证码
     * @return 返回执行后的结果
     */
    @Override
    public Map<String, Object> loginByPhoneAndVerificationCodeOnWebChat(String channelCode, String phone, String webchat, String verificationCode) {
        return null;
    }

    /**
     * 根据微信号和密码登录
     *
     * @param channelCode 渠道编码
     * @param webchat     微信号
     * @param password    密码
     * @return 返回执行后的结果
     */
    @Override
    public Map<String, Object> loginByWebchat(String channelCode, String webchat, String password) {
        return null;
    }

    /**
     * 根据微信号和密码登录
     *
     * @param channelCode 渠道编码
     * @param idCard      身份证号
     * @return 返回执行后的结果
     */
    @Override
    public Map<String, Object> loginOutByWebchat(String channelCode, String idCard) {
        return null;
    }


    /**
     * 查询用户基本信息（返回基本信息、绑定设备微信号信息、关联患者信息）
     * 还未针对授权渠道进行限制
     *
     * @param idCard      身份证号
     * @param channelCode 渠道编码
     * @param user        用户
     * @return
     */
    @Override
    public Map<String, Object> loadInfo(String idCard, String channelCode, String user) {
        Map<String, Object> params = new HashMap<>(16);
        Map<String, Object> res = new HashMap<>(16);
        List<Map<String, Object>> cards = new ArrayList<>();
        params.put("username", user);
        Map<String, Object> userDaoRes = userDao.findOne(params);
//        params.remove("username");
//        if (idCard == null || "".equals(idCard)) {
        String personId = (String) userDaoRes.get("personId");
//        }
        params.put("personId", personId);
        Map<String, Object> personDaoRes = personDao.findOne(params);
        if (personDaoRes != null) {
            res.put("personId", personDaoRes.get("personId"));
            res.put("phone", personDaoRes.get("phone"));
            res.put("name", personDaoRes.get("name"));
            res.put("idCard", personDaoRes.get("personId"));
            res.put("sex", personDaoRes.get("sex"));
            res.put("insurNo", personDaoRes.get("insurNo"));
//        }
            res.put("dateOfBirth", DataFormatUtils.getSimpleTimeString((Date) personDaoRes.get("dateOfBirth")));
        }
        if (idCard != null) {
            cards = treatmentCardDao.find(params);
        }
        if (userDaoRes == null || userDaoRes.isEmpty()) {
            res = new HashMap<>(16);
            res.put(ResponseMessage.RES_CODE, "-3");
            res.put(ResponseMessage.MESSAGE, "未找到相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到相关记录");
        } else {
            res.put("phone", personDaoRes.get("phone"));
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE, "操作成功");
            res.put(ResponseMessage.MESSAGE_IN, "操作成功");
            res.put(ResponseMessage.MESSAGE_OUT, "操作成功");
        }
        if (!("0".equals(cards.size()))) {
            res.put("cards", cards);
        }
        return res;
    }

    /**
     * 注销登录的用户
     *
     * @param channelCode 渠道编码
     * @param username    用户名
     * @param imei        手机设备IMEI号
     * @param openId      微信或其他网页登录唯一身份识别码
     * @param source      来源：1.安卓，2.IOS  3微网站
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
    public Map<String, Object> logout(String channelCode, String username, String imei, String openId, String source) {
        Map<String, Object> res = new HashMap<>(16);
        TokenProvider.removeToken(username);
        String nowDate = DataFormatUtils.getTimeString(new Date());
        Map<String, Object> params = new HashMap<>(16);
        List<Map<String, Object>> loginRes = new ArrayList<>();
        params.put("loginUser", username);
        params.put("loginStatus", 0);
        if ("1".equals(source) || "2".equals(source)) {
            params.put("imei", imei);
            loginRes = userLoginAndLogoutRecordDao.find(params);
        } else if ("3".equals(source)) {
            params.put("openId", openId);
            loginRes = userLoginAndLogoutRecordDao.find(params);
        }
        if (loginRes.size() != 0) {
            for (Map<String, Object> subMap : loginRes) {
                //loginStatus=1 : 主动注销
                subMap.put("loginStatus", 1);
                subMap.put("logoutTime", nowDate);
                subMap.put("modifyTime", nowDate);
                userLoginAndLogoutRecordDao.modify(subMap);
            }
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE, "注销成功");
            res.put(ResponseMessage.MESSAGE_IN, "注销成功");
            res.put(ResponseMessage.MESSAGE_OUT, "注销成功");
        } else {
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE, "用户已注销");
            res.put(ResponseMessage.MESSAGE_IN, "用户已注销");
            res.put(ResponseMessage.MESSAGE_OUT, "用户已注销");
        }

        return res;
    }

    /**
     * 根据openID查询用户信息
     *
     * @param channelCode 渠道编码
     * @param openId      身份认证ID
     * @return
     */
    @Override
    public Map<String, Object> loadUserInfoByOpenId(String channelCode, String openId) {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> params = new HashMap<>(16);
        params.put("openId", openId);
        params.put("loginStatus", 0);
        List<Map<String, Object>> loginResList = userLoginAndLogoutRecordDao.find(params);
        if (loginResList.size() != 0) {
            String personId = null;
            String user = null;
            String defaultname = null;
            String defaultuser = null;
            String defaultpersonId = null;

            for (Map<String, Object> subMap : loginResList) {
                user = (String) subMap.get("loginUser");
            }
            params.remove("openId");
            params.remove("loginStatus");
            params.put("username", user);
            Map<String, Object> userRes = userDao.findOne(params);
            if (userRes != null) {
                String state = (String) userRes.get("state");
                if ("1".equals(state)) {
                    personId = (String) userRes.get("personId");
                    params.put("personId", personId);
                    Map<String, Object> personRes = personDao.findOne(params);
                    String name = (String) personRes.get("name");
                    String phone = (String) personRes.get("phone");
                    defaultname = (String) userRes.get("name");
                    defaultpersonId = (String) userRes.get("idCard");
                    res.put("personId", personId);
                    res.put("user", phone);
                    res.put("name", name);
                    res.put("defaultname", defaultname);
                    res.put("defaultuser", user);
                    res.put("defaultpersonId", defaultpersonId);
                    res.put(ResponseMessage.RES_CODE, "0");
                    res.put(ResponseMessage.MESSAGE, "查询成功");
                    res.put(ResponseMessage.MESSAGE_IN, "查询成功");
                    res.put(ResponseMessage.MESSAGE_OUT, "查询成功");
                } else {
                    res.put(ResponseMessage.RES_CODE, "-1");
                    res.put(ResponseMessage.MESSAGE, "请重新登录！");
                    res.put(ResponseMessage.MESSAGE_IN, "请重新登录！");
                    res.put(ResponseMessage.MESSAGE_OUT, "请重新登录！");
                }
            } else {
                res.put(ResponseMessage.RES_CODE, "-1");
                res.put(ResponseMessage.MESSAGE, "请重新登录！");
                res.put(ResponseMessage.MESSAGE_IN, "请重新登录！");
                res.put(ResponseMessage.MESSAGE_OUT, "请重新登录！");
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE, "请重新登录！");
            res.put(ResponseMessage.MESSAGE_IN, "请重新登录！");
            res.put(ResponseMessage.MESSAGE_OUT, "请重新登录！");
        }

        return res;
    }

    /**
     * 修改默认就诊人
     *
     * @param channelCode 渠道编码
     * @param personId    就诊人ID
     * @param user        用户
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
    public Map<String, Object> modifyDefaultPersonHandler(String channelCode, String personId, String user) {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> params = new HashMap<>(16);
        params.put("personId", personId);
        params.put("username", user);
        userDao.modify(params);
        res.put(ResponseMessage.RES_CODE, "0");
        res.put(ResponseMessage.MESSAGE, "默认就诊人修改成功");
        res.put(ResponseMessage.MESSAGE_IN, "默认就诊人修改成功");
        res.put(ResponseMessage.MESSAGE_OUT, "默认就诊人修改成功");
        return res;
    }

    /**
     * 检查手机号状态
     *
     * @param channelCode
     * @param phone
     * @return
     */
    @Override
    public Map<String, Object> checkPhoneStatus(String channelCode, String phone) {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> personParams = new HashMap<>(16);
        personParams.put("username", phone);
        Map<String, Object> userMap = userDao.findOne(personParams);
        if (userMap != null) {
            res.put("phoneStatus", "1");
            res.put("phoneStatusName", "手机号已被注册");
        } else {
            res.put("phoneStatus", "0");
            res.put("phoneStatusName", "手机号未被注册");
        }
        res.put(ResponseMessage.RES_CODE, "0");
        res.put(ResponseMessage.MESSAGE_IN, "查询成功");
        res.put(ResponseMessage.MESSAGE_OUT, "查询成功");
        res.put(ResponseMessage.MESSAGE, "查询成功");
        return res;
    }

    /**
     * 校验验证码
     *
     * @param channelCode 渠道编码
     * @param phone       手机号
     * @param vcode       验证码
     * @return
     */
    @Override
    public Map<String, Object> verificationCodeHandler(String channelCode, String phone, String vcode) {
        Map<String, Object> res = new HashMap<>(16);
        try {
            verificationCodeSupport.checkVerificationCode(channelCode, phone, vcode);
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "校验成功");
            res.put(ResponseMessage.MESSAGE_OUT, "校验成功");
            res.put(ResponseMessage.MESSAGE, "校验成功");
        } catch (Exception e) {
            e.printStackTrace();
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE_IN, "校验失败");
            res.put(ResponseMessage.MESSAGE_OUT, "校验失败");
            res.put(ResponseMessage.MESSAGE, "校验失败");
        }
        return res;
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
    public Map<String, Object> deleteUser(String username) {
        Map<String, Object> res = new HashMap<>();
        Map<String, Object> params = new HashMap<>();
        try {
            params.put("username", username);
            Map<String, Object> resUserDao = userDao.findOne(params);
            userDao.delete(params);
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "操作成功");
            res.put(ResponseMessage.MESSAGE_OUT, "操作成功");
            res.put(ResponseMessage.MESSAGE, "操作成功");
        } catch (Exception e) {
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE_IN, "操作失败");
            res.put(ResponseMessage.MESSAGE_OUT, "操作失败");
            res.put(ResponseMessage.MESSAGE, "操作失败");
            e.printStackTrace();
        }
        return res;
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
    public Map<String, Object> deletePerson(String personId) {
        Map<String, Object> res = new HashMap<>();
        Map<String, Object> params = new HashMap<>();
        try {
            params.put("personId", personId);
            Map<String, Object> resPersonDao = personDao.findOne(params);
            String relatedUserId = "无";
            relatedUserId = (String) resPersonDao.get("relatedUserId");
            params.put("relatedUserId", relatedUserId);
            personDao.delete(params);
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "操作成功");
            res.put(ResponseMessage.MESSAGE_OUT, "操作成功");
            res.put(ResponseMessage.MESSAGE, "操作成功");
        } catch (Exception e) {
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE_IN, "操作失败");
            res.put(ResponseMessage.MESSAGE_OUT, "操作失败");
            res.put(ResponseMessage.MESSAGE, "操作失败");
            e.printStackTrace();
        }
        return res;
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
    public Map<String, Object> deleteAllPerson(String relatedUserId) {
        Map<String, Object> res = new HashMap<>();
        Map<String, Object> params = new HashMap<>();
        try {
            params.put("relatedUserId", relatedUserId);
            List<Map<String, Object>> personList = this.personDao.find(params);
            personDao.delete(params);
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "操作成功");
            res.put(ResponseMessage.MESSAGE_OUT, "操作成功");
            res.put(ResponseMessage.MESSAGE, "操作成功");
        } catch (Exception e) {
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE_IN, "操作失败");
            res.put(ResponseMessage.MESSAGE_OUT, "操作失败");
            res.put(ResponseMessage.MESSAGE, "操作失败");
            e.printStackTrace();
        }
        return res;
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
    public Map<String, Object> feedBack(String serialNo, String hospitalCode, String username, String feedContent, String feedDate, String state) {
        Map<String, Object> res = new HashMap<>();
        Map<String, Object> params = new HashMap<>();
        try {
            params.put("serialNo", serialNo);
            params.put("hospitalCode", "0001");
            params.put("username", username);
            params.put("feedContent", feedContent);
            List<Map<String, Object>> resfeedBack = feedBackDao.find(params);
            params.put("feedDate", DataFormatUtils.getTimeString(new Date()));
            params.put("state", "0");
            feedBackDao.add(params);
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "反馈成功");
            res.put(ResponseMessage.MESSAGE_OUT, "反馈成功");
            res.put(ResponseMessage.MESSAGE, "反馈成功");
        } catch (Exception e) {
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE_IN, "添加出错");
            res.put(ResponseMessage.MESSAGE_OUT, "添加出错");
            res.put(ResponseMessage.MESSAGE, "添加出错");
            e.printStackTrace();
        }
        return res;
    }


    @Override
    public Map<String, Object> loadSymptomData(String channelCode, String hospitalCode, String partId) {
        Map<String, Object> res = new HashMap<>();
        Map<String, Object> params = new HashMap<>();
        if (StringUtils.hasLength(partId)) {
            params.put("partId", partId);
        } else {
            params.put("partId", "7");
        }
        List<Map<String, Object>> data = dzSymptomDao.find(params);
        res.put("symptomList", data);
        res.put(ResponseMessage.RES_CODE, "0");
        res.put(ResponseMessage.MESSAGE_IN, "加载成功");
        res.put(ResponseMessage.MESSAGE_OUT, "加载成功");
        res.put(ResponseMessage.MESSAGE, "加载成功");
        return res;
    }

    @Override
    public Map<String, Object> loadSymMapData(String channelCode, String hospitalCode, String symId) {
        Map<String, Object> res = new HashMap<>();
        Map<String, Object> params = new HashMap<>();
        params.put("symId", symId);
        List<Map<String, Object>> data = dzSymMapDao.find(params);
        res.put("symMapList", data);
        res.put(ResponseMessage.RES_CODE, "0");
        res.put(ResponseMessage.MESSAGE_IN, "加载成功");
        res.put(ResponseMessage.MESSAGE_OUT, "加载成功");
        res.put(ResponseMessage.MESSAGE, "加载成功");
        return res;
    }

    @Override
    public Map<String, Object> loadDzDeptClass(String channelCode, String hospitalCode, List<String> symMapIdList) {
        Map<String, Object> res = new HashMap<>();
        Map<String, Object> params = new HashMap<>();
        List<Map<String, Object>> resMapList = new ArrayList<>();
        Set set = new HashSet();
        if (symMapIdList != null && !symMapIdList.isEmpty()) {
            for (String temp : symMapIdList) {
                Map<String, Object> subParams = new HashMap<>();
                subParams.put("symMapId", temp);
                List<Map<String, Object>> mapList = dzSymMapperDao.find(subParams);
                for (Map<String, Object> map : mapList) {
                    params.put("deptClassType", map.get("dept_class"));
                    List<Map<String, Object>> resdeptList = deptDao.find(params);
                    map.put("deptClassCode", map.get("dept_class"));
                    map.put("subDepts", resdeptList);
                    map.remove("symMapId");
                    set.add(map);
                }
//                resMapList.addAll(set);
            }
        }
        res.put("dataList", set);
        res.put(ResponseMessage.RES_CODE, "0");
        res.put(ResponseMessage.MESSAGE_IN, "加载成功");
        res.put(ResponseMessage.MESSAGE_OUT, "加载成功");
        res.put(ResponseMessage.MESSAGE, "加载成功");
        return res;
    }

    @Override
    public Map<String, Object> loadDeptOfClass(String channelCode, String hospitalCode, String dept_class) {
        Map<String, Object> res = new HashMap<>();
        Map<String, Object> params = new HashMap<>();
        params.put("deptClassType", dept_class);
        List<Map<String, Object>> resList = deptDao.find(params);
        res.put("deptOfClassList", resList);
        res.put(ResponseMessage.RES_CODE, "0");
        res.put(ResponseMessage.MESSAGE_IN, "加载成功");
        res.put(ResponseMessage.MESSAGE_OUT, "加载成功");
        res.put(ResponseMessage.MESSAGE, "加载成功");
        return res;
    }

    @Override
    public Map<String, Object> loadDoctor(String channelCode, String hospitalCode, String docName) {
        Map<String, Object> res = new HashMap<>();
        Map<String, Object> params = new HashMap<>();
        String searchText = new StringBuilder("%").append(docName).append("%").toString();
        params.put("doctorName", searchText);
        List<Map<String, Object>> resList = doctorDao.find(params);
        List<Map<String, Object>> dataList = new ArrayList<>();
        if (resList != null && resList.size() > 0) {
            for (Map<String, Object> subMap : resList) {
                Map<String, Object> paramsMap = new HashMap<>(16);
                paramsMap.put("docName", subMap.get("doctorName"));
                paramsMap.put("major", subMap.get("major"));
                paramsMap.put("docId", subMap.get("doctorCode"));
                paramsMap.put("url", subMap.get("iconUrl"));
                paramsMap.put("title", Dialect.getDoctorTitleName((String) subMap.get("titleCode")));
                paramsMap.put("deptId", subMap.get("deptCode"));
                paramsMap.put("introduction", subMap.get("introduce"));
                paramsMap.put("sex", subMap.get("sex"));
                params.put("deptCode", subMap.get("deptCode"));
                params.put("hospitalCode", hospitalCode);
                params.put("channelCode", channelCode);
                Map<String, Object> reshospitalDeptDao = deptDao.findOne(params);
                paramsMap.put("deptName", reshospitalDeptDao.get("deptName"));
                dataList.add(paramsMap);
            }
        }
        res.put("dataList", dataList);
        res.put(ResponseMessage.RES_CODE, "0");
        res.put(ResponseMessage.MESSAGE_IN, "加载成功");
        res.put(ResponseMessage.MESSAGE_OUT, "加载成功");
        res.put(ResponseMessage.MESSAGE, "加载成功");
        return res;
    }

    /**
     * 根据openID查询用户信息(加医保)
     *
     * @param channelCode 渠道编码
     * @param openId      身份认证ID
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
    public Map<String, Object> loadInsuranceUserInfoByOpenId(String channelCode, String openId) {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> params = new HashMap<>(16);
        params.put("openId", openId);
        params.put("loginStatus", 0);
        List<Map<String, Object>> loginResList = userLoginAndLogoutRecordDao.find(params);
        if (loginResList.size() != 0) {
            String personId = null;
            String user = null;
            String defaultname = null;
            String defaultuser = null;
            String defaultpersonId = null;

            for (Map<String, Object> subMap : loginResList) {
                user = (String) subMap.get("loginUser");
            }
            params.remove("openId");
            params.remove("loginStatus");
            params.put("username", user);
            Map<String, Object> userRes = userDao.findOne(params);
            if (userRes != null) {
                if ((userRes.get("personId") == null)) {
                    res.put(ResponseMessage.RES_CODE, "-1");
                    res.put(ResponseMessage.MESSAGE, "请重新注册！");
                    res.put(ResponseMessage.MESSAGE_IN, "请重新注册！");
                    res.put(ResponseMessage.MESSAGE_OUT, "请重新注册！");
                    String sfz = (String) userRes.get("idCard");
                    Map<String, Object> person = new HashMap<>(16);
                    person.put("personId", sfz);
                    Map<String, Object> resPerson = personDao.findOne(person);
                    String relatedUserId = (String) resPerson.get("relatedUserId");
                    String username = (String) resPerson.get("phone");
                    Map<String, Object> person1 = new HashMap<>(16);
                    person1.put("relatedUserId", relatedUserId);
                    person1.put("username", username);
                    userDao.delete(person1);
                    personDao.delete(person1);
                } else {
                    String state = (String) userRes.get("state");
                    if ("1".equals(state)) {
                        personId = (String) userRes.get("personId");
                        params.put("personId", personId);
                        Map<String, Object> personRes = personDao.findOne(params);
                        String name = (String) personRes.get("name");
                        String phone = (String) personRes.get("phone");
                        defaultname = (String) userRes.get("name");
                        defaultpersonId = (String) userRes.get("idCard");
                        String insurNo = (String) personRes.get("insurNo");
                        res.put("personId", personId);
                        res.put("user", phone);
                        res.put("name", name);
                        res.put("insurNo", insurNo);
                        res.put("defaultname", defaultname);
                        res.put("defaultuser", user);
                        res.put("defaultpersonId", defaultpersonId);
                        res.put(ResponseMessage.RES_CODE, "0");
                        res.put(ResponseMessage.MESSAGE, "查询成功");
                        res.put(ResponseMessage.MESSAGE_IN, "查询成功");
                        res.put(ResponseMessage.MESSAGE_OUT, "查询成功");
                    } else {
                        res.put(ResponseMessage.RES_CODE, "-1");
                        res.put(ResponseMessage.MESSAGE, "请重新登录！");
                        res.put(ResponseMessage.MESSAGE_IN, "请重新登录！");
                        res.put(ResponseMessage.MESSAGE_OUT, "请重新登录！");
                    }
                }
//                else{
//                    res.put(ResponseMessage.RES_CODE, "-1");
//                    res.put(ResponseMessage.MESSAGE, "请重新注册！");
//                    res.put(ResponseMessage.MESSAGE_IN, "请重新注册！");
//                    res.put(ResponseMessage.MESSAGE_OUT, "请重新注册！");
//                    String sfz = (String) userRes.get("idCard");
//                    Map<String, Object> person = new HashMap<>(16);
//                    person.put("personId",sfz);
//                    Map<String, Object> resPerson = personDao.findOne(person);
//                    String relatedUserId =(String) resPerson.get("relatedUserId");
//                    String username =(String) resPerson.get("phone");
//                    Map<String, Object> person1 = new HashMap<>(16);
//                    person1.put("relatedUserId",relatedUserId);
//                    person1.put("username",username);
//                    userDao.delete(person1);
//                    personDao.delete(person1);
//                }
            } else {
                res.put(ResponseMessage.RES_CODE, "-1");
                res.put(ResponseMessage.MESSAGE, "请重新登录！");
                res.put(ResponseMessage.MESSAGE_IN, "请重新登录！");
                res.put(ResponseMessage.MESSAGE_OUT, "请重新登录！");
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE, "请重新登录！");
            res.put(ResponseMessage.MESSAGE_IN, "请重新登录！");
            res.put(ResponseMessage.MESSAGE_OUT, "请重新登录！");
        }

        return res;
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
    public Map<String, Object> modifyInsurance(String channelCode, String personId, String insurNo) {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> params = new HashMap<>(16);
        params.put("personId", personId);
        params.put("insurNo", insurNo);
        Map<String, Object> personRes = personDao.findOne(params);
        if (personRes != null) {
            personDao.modify(params);
            res.put("insurNo", insurNo);
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "操作成功");
            res.put(ResponseMessage.MESSAGE_OUT, "操作成功");
            res.put(ResponseMessage.MESSAGE, "操作成功");
        }
        return res;
    }

    @Override
    public Map<String, Object> loadOpenId(String user, String channel) {
        Map<String, Object> res = new HashMap<>();
        Map<String, Object> params = new HashMap<>();
        params.put("loginUser", user);
        params.put("loginStatus", "0");
        List<Map<String, Object>> resOpenIdList = userLoginAndLogoutRecordDao.find(params);
        res.put("openId", resOpenIdList.get(0).get("openId"));
        res.put(ResponseMessage.RES_CODE, "0");
        res.put(ResponseMessage.MESSAGE_IN, "加载成功");
        res.put(ResponseMessage.MESSAGE_OUT, "加载成功");
        res.put(ResponseMessage.MESSAGE, "加载成功");
        return res;
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
    public Map<String, Object> UserVerificationStateUpdateAgent(String relatedUserId, String personId, String state, String verificationState) {
        Map<String, Object> params = new HashMap<>();
        Map<String, Object> res = new HashMap<>();
        params.put("relatedUserId",relatedUserId);
        params.put("personId",personId);
        params.put("oldState",state);
        params.put("verificationState",verificationState);
        personAndUserRelationDao.modify(params);
        res.put(ResponseMessage.RES_CODE, "0");
        res.put(ResponseMessage.MESSAGE_IN, "加载成功");
        res.put(ResponseMessage.MESSAGE_OUT, "加载成功");
        res.put(ResponseMessage.MESSAGE, "成功");
        return res;
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
    public Map<String, Object> updatePersonName(String personId,String phone,String name) {
        Map<String, Object> res = new HashMap<>();
        Map<String, Object> params = new HashMap<>();
        try {
            params.put("personId", personId);
            params.put("phone", phone);
            params.put("name", name);
            personDao.modify(params);
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "操作成功");
            res.put(ResponseMessage.MESSAGE_OUT, "操作成功");
            res.put(ResponseMessage.MESSAGE, "操作成功");
        } catch (Exception e) {
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE_IN, "操作失败");
            res.put(ResponseMessage.MESSAGE_OUT, "操作失败");
            res.put(ResponseMessage.MESSAGE, "操作失败");
            e.printStackTrace();
        }
        return res;
    }
}
